home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / bin / openapp < prev    next >
Encoding:
Text File  |  2010-05-31  |  10.7 KB  |  341 lines

  1. #!/bin/sh
  2. #
  3. # openapp.  Generated from openapp.in by configure.
  4. #
  5. # Copyright (C) 1997 - 2006 Free Software Foundation, Inc.
  6. #
  7. # Author: Ovidiu Predescu <ovidiu@net-community.com>
  8. # Date: October 1997
  9. # Author: Nicola Pero <n.pero@mi.flashnet.it>
  10. # Date: 2002 - 2006
  11. #
  12. # This file is part of the GNUstep Makefile Package.
  13. #
  14. # This library is free software; you can redistribute it and/or
  15. # modify it under the terms of the GNU General Public License
  16. # as published by the Free Software Foundation; either version 3
  17. # of the License, or (at your option) any later version.
  18. # You should have received a copy of the GNU General Public
  19. # License along with this library; see the file COPYING.
  20. # If not, write to the Free Software Foundation,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22.  
  23. # Please note that all local variables are prefixed with 'openapp_' to
  24. # avoid conflicts.
  25.  
  26. # Try to execute the application passed as argument. The application
  27. # is searched through the GNUstep directories if a complete or
  28. # relative path name is not specified. The arguments passed after the
  29. # application name are passed unmodified to the application. The
  30. # option --debug case the application to be launched inside a debugger
  31. # (originally we had a separate script, called debugapp, for that).
  32.  
  33. if [ -z "$1" ]; then
  34.   echo usage: `basename "$0"` [--find] [--debug] application [arguments...]
  35.   echo `basename "$0"` --help for more help
  36.   exit 1
  37. fi
  38.  
  39. # Here read all the --find/--debug/--help/etc arguments, up to the
  40. # first non-argument.  That one is the name of the application we want
  41. # to launch.  We leave any parameters after the app name unchanged so
  42. # that we have them available in $@ to give to the application.
  43.  
  44. while [ x"$1" != x ]; do
  45.   case "$1" in
  46.   --help)
  47.     echo usage: `basename "$0"` [--find] [--debug] application [arguments...]
  48.     echo
  49.     echo "application is the complete or relative name of the application"
  50.     echo "program with or without the .app extension, like Ink.app."
  51.     echo
  52.     echo "[arguments...] are the arguments to the application."
  53.     echo 
  54.     echo "If --find is used, openapp prints out the full path of the application "
  55.     echo "executable which would be executed, without actually executing it.  It"
  56.     echo "will also list all paths that are attempted."
  57.     echo 
  58.     echo "If --debug is used, openapp starts the application in the debugger "
  59.     echo "(by default gdb, but can be changed using the GDB shell variable, "
  60.     echo "or the --gdb=... argument)."
  61.     echo
  62.     echo "A rarely used option is --library-combo=... which can be used"
  63.     echo "in non-flattened (advanced/non standard) setups to start up"
  64.     echo "the application using a specified library-combo."
  65.     echo
  66.     echo "Invoking this program as 'debugapp' is equivalent to using the --debug"
  67.     echo "option."
  68.     exit 0
  69.     ;;
  70.   --find)
  71.     openapp_only_find=yes;
  72.     if [ -z "$2" ]; then
  73.       echo "Missing application name.  Please try openapp --help for more help."
  74.       exit 1
  75.     fi
  76.     shift;;
  77.   --debug)
  78.     # debugapp manually sets this variable before invoking openapp.
  79.     # So if you change this, make sure to update debugapp too.
  80.     openapp_debug_mode=yes;
  81.     if [ -z "$2" ]; then
  82.       echo "Missing application name.  Please try openapp --help for more help."
  83.       exit 1
  84.     fi
  85.     shift;;
  86.   --gdb=*)
  87.     GDB=`echo "$1" | sed 's/--gdb=//'`
  88.     if [ -z "$2" ]; then
  89.       echo "Missing application name.  Please try openapp --help for more help."
  90.       exit 1
  91.     fi
  92.     shift;;
  93.   --library-combo=*)
  94.     # FIXME - Reset the existing library combo environment ?  We haven't read
  95.     # the config file yet, so GNUSTEP_MAKEFILES might not be set yet! :-/
  96.     # . $GNUSTEP_MAKEFILES/GNUstep-reset.sh
  97.     LIBRARY_COMBO=`echo "$1" | sed 's/--library-combo=//'`
  98.     if [ -z "$2" ]; then
  99.       echo "Missing application name.  Please try openapp --help for more help."
  100.       exit 1
  101.     fi
  102.     shift;;
  103.   *)
  104.     openapp_app="$1"; 
  105.     shift;
  106.     # Exit from the loop so the remaining arguments are in $@ and we
  107.     # can pass them unchanged to the application.
  108.     break;;
  109.   esac
  110. done
  111.  
  112. # Try to determine GNUSTEP_MAKEFILES to source GNUstep.sh
  113. if [ -z "$GNUSTEP_CONFIG_FILE" ]; then
  114.   GNUSTEP_CONFIG_FILE=/etc/GNUstep/GNUstep.conf
  115. fi
  116.  
  117. if [ -z "$GNUSTEP_USER_CONFIG_FILE" ]; then
  118.   GNUSTEP_USER_CONFIG_FILE=.GNUstep.conf
  119. fi
  120.  
  121. if [ -f "$GNUSTEP_CONFIG_FILE" ]; then
  122.   . "$GNUSTEP_CONFIG_FILE"
  123. fi
  124.  
  125. GNUSTEP_HOME=~
  126.  
  127. if [ -n "$GNUSTEP_USER_CONFIG_FILE" ]; then
  128.   case "$GNUSTEP_USER_CONFIG_FILE" in 
  129.     /*) # An absolute path
  130.         if [ -f "$GNUSTEP_USER_CONFIG_FILE" ]; then
  131.           . "$GNUSTEP_USER_CONFIG_FILE"
  132.         fi;;
  133.      *) # Something else
  134.         if [ -f "$GNUSTEP_HOME/$GNUSTEP_USER_CONFIG_FILE" ]; then
  135.           . "$GNUSTEP_HOME/$GNUSTEP_USER_CONFIG_FILE"
  136.         fi;;
  137.   esac
  138. fi
  139.  
  140. if [ -z "$GNUSTEP_MAKEFILES" ]; then
  141.   GNUSTEP_MAKEFILES="/usr/share/GNUstep/Makefiles"
  142. fi
  143. # OK, we now have GNUSTEP_MAKEFILES, source GNUstep.sh
  144.  
  145. # Ahm ... TODO: we shouldn't need to source GNUstep.sh if we are
  146. # running flattened. :-) Anyway it won't harm (just slow things down a
  147. # lot).  This must be after parsing the --library-combo parameter.
  148.  
  149. # Also, we'd like to get the GNUSTEP_*_APPS directories so we can
  150. # search them, so tell GNUstep.sh to export all variabes.
  151. GNUSTEP_SH_EXPORT_ALL_VARIABLES=yes
  152. . "$GNUSTEP_MAKEFILES/GNUstep.sh"
  153. unset GNUSTEP_SH_EXPORT_ALL_VARIABLES
  154.  
  155. if [ -z "$GNUSTEP_IS_FLATTENED" ]; then
  156.   GNUSTEP_IS_FLATTENED=yes
  157. fi
  158.  
  159. if [ -z "$GDB" ]; then
  160.   GDB=gdb
  161. fi
  162.  
  163. # Remove leading slashes at the end of the application name
  164. openapp_app=`echo "$openapp_app" | sed 's%/*$%%'`
  165.  
  166. # Check if the user has provided the .app suffix; if not, add it.
  167. # Save the appname (without the .app suffix) if we have it, so
  168. # we save a sed (to remove the .app suffix) later on.
  169. case "$openapp_app" in
  170.   *.app) openapp_appname="";;
  171.   *)     openapp_appname="$openapp_app"; openapp_app="$openapp_app.app";;
  172. esac
  173.  
  174. case "$openapp_app" in
  175.     /*) # An absolute path.
  176.       if [ -n "$openapp_only_find" ]; then
  177.         echo "Trying $openapp_app..."
  178.       fi
  179.       if [ -d "$openapp_app" ]; then
  180.     openapp_full_appname="$openapp_app"
  181.       fi
  182.       ;;
  183.     */*) # A relative path
  184.       if [ -n "$openapp_only_find" ]; then
  185.         echo "Trying $openapp_app..."
  186.       fi
  187.       if [ -d "$openapp_app" ]; then
  188.     openapp_full_appname=`(cd "$openapp_app"; pwd)`
  189.       fi
  190.       ;;
  191.     *)
  192.       # We should first search the standard GNUstep locations.
  193.       for openapp_dir in "$GNUSTEP_USER_APPS" "$GNUSTEP_LOCAL_APPS" "$GNUSTEP_NETWORK_APPS" "$GNUSTEP_SYSTEM_APPS"; do
  194.       # Standard locations ... in $domain_apps/$openapp_app
  195.           if [ -n "$openapp_only_find" ]; then
  196.             echo "Trying $openapp_dir/$openapp_app..."
  197.           fi
  198.       if [ -d "$openapp_dir/$openapp_app" ]; then
  199.         openapp_full_appname=`(cd "$openapp_dir/$openapp_app"; pwd)`
  200.         break
  201.       fi
  202.       done
  203.       if [ -z "$openapp_full_appname" ]; then
  204.  
  205.         # Now search the Admin Apps locations ... but only if they are
  206.         # Administrators.  But how do we know if we are an Admin ?  We
  207.         # need a portable way.  Our first attempt here is to check if
  208.         # we can write to an ADMIN directory, we are an Administrator.
  209.         # So, if any GNUSTEP_*_ADMIN_APPS directory exists and we can
  210.         # write to it, then we consider us enough powerful to execute
  211.         # applications from it and search in it.
  212.         #
  213.         # FIXME: Unfortunately, this doesn't work if the Admin directory
  214.         # is mounted read-only, so a better test is required!
  215.         #
  216.         for openapp_dir in "$GNUSTEP_USER_ADMIN_APPS" "$GNUSTEP_LOCAL_ADMIN_APPS" "$GNUSTEP_NETWORK_ADMIN_APPS" "$GNUSTEP_SYSTEM_ADMIN_APPS"; do
  217.       if [ -d "$openapp_dir"  -a  -w "$openapp_dir" ]; then 
  218.             if [ -n "$openapp_only_find" ]; then
  219.               echo "Trying $openapp_dir/$openapp_app..."
  220.             fi
  221.         if [ -d "$openapp_dir/$openapp_app" ]; then 
  222.           openapp_full_appname=`(cd "$openapp_dir/$openapp_app"; pwd)`
  223.           break
  224.         fi
  225.           fi
  226.         done
  227.  
  228.     # And now search the standard PATH (may include '.')
  229.     old_IFS="$IFS"
  230.     IFS=:
  231.     for openapp_dir in $PATH; do
  232.           if [ -n "$openapp_only_find" ]; then
  233.             echo "Trying $openapp_dir/$openapp_app..."
  234.           fi
  235.       if [ -d "$openapp_dir/$openapp_app" ]; then
  236.         openapp_full_appname=`(cd "$openapp_dir/$openapp_app"; pwd)`
  237.             break
  238.       fi
  239.     done
  240.     IFS="$old_IFS"
  241.       fi
  242.     ;;
  243. esac
  244.  
  245. if [ -z "$openapp_full_appname" ]; then
  246.   echo "Can't find the required application: $openapp_app!"
  247.   if [ -d "./$openapp_app" ]; then
  248.     echo "There is a $openapp_app in this directory; please use 'openapp ./$openapp_app' if you want to open it!"
  249.   fi
  250.   exit 1
  251. fi
  252.  
  253. # get base app name
  254. if [ -z "$openapp_appname" ]; then
  255.   openapp_appname=`echo "$openapp_app" | sed 's/\.app$//'`
  256. fi
  257. openapp_appname=`basename "$openapp_appname"`
  258.  
  259. if [ -z "$EXEEXT" ]; then
  260.   EXEEXT=
  261. fi
  262.  
  263. if [ -n "$EXEEXT" ]; then
  264.   openapp_appname="$openapp_appname$EXEEXT"
  265. fi
  266.  
  267. if [ "$GNUSTEP_IS_FLATTENED" = "no" ]; then
  268.  
  269.   case "$LIBRARY_COMBO" in
  270.     apple-*) openapp_app_executable="$openapp_full_appname/Contents/MacOS/$openapp_appname";;
  271.     *)       openapp_app_executable="$openapp_full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$openapp_appname";;
  272.   esac
  273.  
  274. else
  275.  
  276.   case "$LIBRARY_COMBO" in
  277.     apple-*) openapp_app_executable="$openapp_full_appname/Contents/MacOS/$openapp_appname";;
  278.     *)       openapp_app_executable="$openapp_full_appname/$openapp_appname";;
  279.   esac
  280.  
  281. fi
  282.  
  283.   
  284. if [ ! -f "$openapp_app_executable" ]; then
  285.   echo "Could not find $openapp_app_executable executable/script"
  286.   exit 1
  287. fi
  288.  
  289. if [ -n "$openapp_only_find" ]; then
  290.   echo " => Using $openapp_app_executable"
  291.   exit 0
  292. fi
  293.  
  294. if [ -n "$openapp_debug_mode" ]; then
  295.  
  296.   # Search for a core file in the current directory.
  297.   openapp_corearg=
  298.   openapp_corefiles="core*"
  299.   for openapp_corefile in $openapp_corefiles; do
  300.     if [ -f "$openapp_corefile" ]; then
  301.       echo "Core image ($openapp_corefile) has been found in working directory. Use it (y/n)? ";
  302.       # Need an argument here for Solaris
  303.       read REPLY;
  304.       if [ $REPLY = y ]; then
  305.         echo "Using it.";
  306.         corearg="--core=$openapp_corefile";
  307.         break;
  308.       else
  309.         echo "Ignoring it.";
  310.       fi
  311.     fi
  312.   done
  313.   unset openapp_corefile
  314.   unset openapp_corefiles
  315.  
  316.   if [ -z "$openapp_corearg" ]; then
  317.  
  318.     # Old versions of gdb don't support --args, so we only use it if
  319.     # 'gdb --help' lists it.
  320.     openapp_args=
  321.     if ("$GDB" --help | grep -e '\-\-args' > /dev/null); then
  322.       openapp_args="--args"
  323.     fi
  324.     # Arguments passed to debugapp are passed over to the
  325.     # application, in the same way as it happens for openapp.
  326.  
  327.     "$GDB" $openapp_args "$openapp_app_executable" "$@"
  328.  
  329.   else
  330.  
  331.     "$GDB" "$openapp_app_executable" "$openapp_corearg"
  332.  
  333.   fi
  334.  
  335. else # non-debug follows
  336.  
  337.   exec "$openapp_app_executable" "$@"
  338.  
  339. fi
  340.